/**
 * Diffie-Hellman Key Exchange implementation
 *
 */

#ifndef	INCOGNITO_DH_H
#define	INCOGNITO_DH_H
#include "bigint.h"

class dh {
	public:
		dh(); // To calculate secret run set_rpubkey()
		dh(bigint p, bigint g, bigint remote_pubkey); // Secret is calculated in constructor


		const bigint& get_pubkey() const { return m_ga; }
		const bigint& get_rpubkey() const { return m_gb; }
		const bigint& get_p() const { return m_p; }
		const bigint& get_g() const { return m_g; }
		const bigint& get_secret() const { return m_zz; }
		bool ok() const { return m_ok; }

		void set_rpubkey(bigint remote_pubkey);

	protected:
		// Generate group parameters (p,g)
		void gen_group_params();

		// Generate private key
		void gen_priv_key();

		// Calculate secret
		void calc_secret();

	private:

		bool		m_ok;	// Is secret calculated?
		
		bigint		m_p;	// Prime number
		bigint		m_g;	// Generator
		bigint		m_a;	// Local private key
		bigint		m_ga;	// Local public key
		bigint		m_gb;	// Remote public key
		bigint		m_zz;	// Established shared secret
		gmp_randstate_t	m_rs;	// Random number generator state
};
#endif	/* INCOGNITO_DH_H */
